package com.ordersystem.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ordersystem.domain.Employee;
import com.ordersystem.domain.EmployeeDistribution;
import com.ordersystem.domain.UpdateEmployeeImg;
import com.ordersystem.mappers.EmployeeMapper;
import com.ordersystem.service.EmployeeService;
import com.ordersystem.utils.PageUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author : asus1020
 * @version : [v1.0]
 * @className : EmployeeServiceImpl
 * @description : [描述说明该类的功能]
 * @createTime : [2022/3/25 20:24]
 * @updateUser : asus1020
 * @updateTime : [2022/3/25 20:24]
 * @updateRemark : [描述说明本次修改内容]
 */
@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Resource
    private EmployeeMapper employeeMapper;

    @Override//根据条件查询员工列表
    public Map findEmployee(String query, Integer pagenum, Integer pagesize) {
        HashMap<String, Object> map = new HashMap<>();
        Page<Object> pageInfo = PageHelper.startPage(pagenum, pagesize);
        List<Employee> employeeList = employeeMapper.findEmployee(query);
        long total = pageInfo.getTotal();
        int pageNum = pageInfo.getPageNum();
        map.put("employees",employeeList);
        map.put("totalPage",total);
        map.put("pagenum",pageNum);
        return map;
    }

    @Override//修改员工状态
    public int updateEmployeeStatus(Integer eid, boolean status) {
        return employeeMapper.updateEmployeeStatus(eid,status);
    }

    @Override//修改员工信息
    public int updateEmployee(Employee employee,Integer rid) {
        return employeeMapper.updateEmployee(employee,rid);
    }

    @Override//删除员工信息
    public int deleteEmployee(Integer eid) {
        return employeeMapper.deleteEmplotee(eid);
    }

    @Override//添加员工信息
    public int addEmployee(Employee employee, Integer rid) {
        employee.setToken(PageUtils.generateToken());
        return employeeMapper.addEmployee(employee,rid);
    }

    @Override//上传员工头像
    public int saveEmployeeHeaderImg(String headerImgPath, Integer eid) {
        return employeeMapper.saveEmployeeHeaderImg(headerImgPath,eid);
    }

    @Override//员工登录
    public Employee login(String username, String password) {
        return employeeMapper.login(username, password);
    }

    @Override
    public int updateEmployeeHeaderImage(UpdateEmployeeImg employeeImg) {
        return employeeMapper.updateEmployeeHeaderImage(employeeImg);
    }

    @Override
    public List<EmployeeDistribution> getEmployeeDistribution() {
        return employeeMapper.getEmployeeDistribution();
    }

    @Override
    public Integer statisticsEmployeeNumberByRid(Integer rid) {
        return employeeMapper.statisticsEmployeeByRid(rid);
    }
}
